package com.js.basic.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.js.basic.domain.BsSupplier;
import com.js.basic.service.IBsSupplierService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 供应商信息Controller
 * 
 * @author ruoyi
 * @date 20240704
 */
@RestController
    @RequestMapping("/supplier")
public class BsSupplierController extends BaseController
{
    @Autowired
    private IBsSupplierService bsSupplierService;

    /**
     * 查询供应商信息列表
     */
    @RequiresPermissions("expert:expert:list")
    @GetMapping("/list")
    public TableDataInfo list(BsSupplier bsSupplier)
    {
        startPage();
        List<BsSupplier> list = bsSupplierService.selectBsSupplierList(bsSupplier);
        return getDataTable(list);
    }


    @GetMapping("/selectSupBySupCode/{supCode}")
    public AjaxResult selectSupBySupCode(@PathVariable("supCode") String supCode){
        return AjaxResult.success(bsSupplierService.selectSupBySupCode(supCode));
    }

    /**
     * 导出供应商信息列表
     */
    @RequiresPermissions("expert:expert:export")
    @Log(title = "供应商信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BsSupplier bsSupplier)
    {
        List<BsSupplier> list = bsSupplierService.selectBsSupplierList(bsSupplier);
        ExcelUtil<BsSupplier> util = new ExcelUtil<BsSupplier>(BsSupplier.class);
        util.exportExcel(response, list, "供应商信息数据");
    }


    /**
     * 新增供应商信息
     */
    @Log(title = "供应商信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BsSupplier bsSupplier)
    {
        return toAjax(bsSupplierService.insertBsSupplier(bsSupplier));
    }

    /**
     * 修改供应商信息
     */
    @RequiresPermissions("expert:expert:edit")
    @Log(title = "供应商信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BsSupplier bsSupplier)
    {
        return toAjax(bsSupplierService.updateBsSupplier(bsSupplier));
    }

    /**
     * 删除供应商信息
     */
    @RequiresPermissions("expert:expert:remove")
    @Log(title = "供应商信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{supCodes}")
    public AjaxResult remove(@PathVariable String[] supCodes)
    {
        return toAjax(bsSupplierService.deleteBsSupplierBySupCodes(supCodes));
    }

    @GetMapping("/login")
    public AjaxResult login(@RequestParam Map<String,Object> map){
        System.out.println("map = " + map);
        BsSupplier bsSupplier = bsSupplierService.selectBsSupplierBySupCode(map);
        System.out.println("bsSupplier = " + bsSupplier);
        if (bsSupplier != null){
            return AjaxResult.success("登入成功！",bsSupplier);
        }
        return AjaxResult.error("账号或密码错误",null);
    }

}
